package com.itheima.service.impl;

import com.itheima.domain.Student;
import com.itheima.mapper.StudentMapper;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class StudentServiceImpl implements StudentService {

    //todo 目前service是位于spring容器中，想要不再容器中得mapper对象，要要不到的
    //todo 只有等到mybatis和spring整合完毕之后，才能要到
    @Autowired
    private StudentMapper studentMapper;

    public List<Student> findAll() {
        System.out.println("findAll方法被调用");

       // return null;
        return studentMapper.findAll();
    }

    public void save(Student student) {
        studentMapper.save(student);

        //模拟异常
        int i=1/0;
    }

    public Student findByNumber(String number) {
        return studentMapper.findByNumber(number);
    }

    public void update(Student student) {
        studentMapper.update(student);
    }

    public void deleteByNumber(String number) {
         studentMapper.deleteByNumber(number);
    }

}
